<%@page import="com.group.board.BoardData"%>
<%@page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<jsp:useBean id="boardMgr" class="com.group.board.BoardMgr"/>
<jsp:useBean id="boardData" class="com.group.board.BoardData"/>
<%
request.setCharacterEncoding("utf-8");

int start, end, pageSu, spage = 1;
int plist;

if(request.getParameter("plist_set")!=null){
	plist = Integer.parseInt(request.getParameter("plist_set"));
	boardMgr.setPlist(plist);
}	

%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>게시판</title>
<link rel="stylesheet" type="text/css" href="board.css"> <!-- css 삽입-->
<script type="text/javascript">
	function check(){
		//alert("aa");
		if(frm.sword.value===""){
			alert("검색어를 입력하시오");
			frm.sword.focus();
			return;
		}
		frm.submit();
	}
</script>
</head>
<body bgcolor="beige">
<jsp:include page="../common/top.jsp" />
	<form id="frm" name="frm" method="post" action="">
	<br>
		<br>
		<h3>&nbsp;&nbsp;
			<b><img src="../img/file.jpg" /> 공지사항 </b>
		</h3><hr>
<table align="right">
	<tr>
		<td>	
			<form action="boardlist.jsp" method="post" name="frm">
				<select name="stype">
					<option value="title" selected="selected"> 글제목</option>
					<option value="cont" >글내용</option>
					<option value="name" >작성자</option>
				</select>
				<input type="text" name="sword">
				<input type="button" value="검 색" onclick="check()">
			</form>
		</td>
	</tr>
</table>
<br>			
<table>
	<tr>
		<td align="right">
			<!-- onfocus="blur()" 눌렀을때 ---- 테두리 사라짐-->
			<input type="button" value="최근목록" onclick="location.href='boardlist.jsp?page=1'">&nbsp;
			<input type="button" value="Add" onclick="location.href='boardwrite.jsp'">&nbsp;
		</td>
	</tr>
	</table>
<table align="right">
		<tr>
			<td>
			<form action="../board/boardlist.jsp"" method="post" name="plist_frm">
				<select name="plist_set">
					<option value="5" selected="selected">5줄보기</option>
					<option value="10">10줄보기</option>
					<option value="15" >15줄보기</option>					
				</select>
				<input type="submit" value="보기">
			</form>
			</td>
		</tr>
	</table>
		
	<table width="100%" border="1">
		<tr bgcolor="ace7ff">
			<th width="30">No</th>
			<th width="150">TITLE</th>
			<th width="150">User Name</th>
			<th width="150">Reg Date</th>
			<th width="150">HitCount</th>
		</tr>
			<%
				request.setCharacterEncoding("utf-8");
				try{
					spage = Integer.parseInt(request.getParameter("page"));
				}catch(Exception e){
					spage =1;
				}
				if(spage <= 0) spage =1;
				
				String type = request.getParameter("stype");// 검색에서 넘어오는 값(작성자, 글제목, 글내용)
				String word = request.getParameter("sword"); // 검색창의 내용
				
				//페이지 단위 작업
				boardMgr.totalList(word, type); //레코드 전체 개수 구함
				pageSu = boardMgr.getPagesu(); //총 페이지 수
				//out.print("총페이지 수 : "+pageSu);
				ArrayList<BoardData> list = boardMgr.getList(word, type, spage);
				for(int i=0; i < list.size(); i++){
					boardData = (BoardData)list.get(i);
					//댓글 들여쓰기
					int nst = boardData.getNested();
					String tab = "";
					String icon="";
					for(int t=0;t<nst;t++){
						tab += "&nbsp;&nbsp;";
						icon += "<img src='../images/re.gif' border='0'>";
					}
			%>
				<tr align="center">
					<td><%= boardData.getNum() %></td>
					<td width="300" align="left" style="padding-left: 10px">
						<%=tab %><%=icon %><a href="boardcontent.jsp?num=<%=boardData.getNum() %>&page=<%=spage%>" onfocus="blur()">
						<%= boardData.getTitle() %>
						</a>
						</td>
					<td><%= boardData.getName() %></td>
					<td><%= boardData.getBdate() %></td>
					<td><%= boardData.getReadcnt() %></td>
				</tr>
			<%
			}
			%>
		</table>
		<br><br><br><br>
			<table align="center">
				<tr>
				<td>
				<%
					for(int p=1; p <=pageSu;p++){
						if( p == spage){
							out.print("<b style='font-size:12pt; color:red'>["+ p+"]</b>");
						}else{
							out.print("<a href='boardlist.jsp?page="+ p+"'>["+p+"]</a>");
						}
					}
				%>
				<br><br>
				</td>
			</table>
	</tr>
</form>
</body>
</html>